package org.video.mine.network;

import android.util.Log;

import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;

import com.alibaba.fastjson.JSONObject;

import org.jsoup.Jsoup;
import org.jsoup.helper.HttpConnection;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import org.video.mine.HomeDocModel;
import org.video.mine.entity.DongHuaEntity;
import org.video.mine.entity.HomeTitleEntity;
import org.video.mine.entity.MovieDetailEntity;
import org.video.mine.entity.MovieInfoEntity;
import org.video.mine.entity.MoviePlayerEntity;
import org.video.mine.entity.PlayListEntity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class JsoupGet {

    public static List<HomeTitleEntity> getHomeTitle(ViewModelStoreOwner context, String url){
        List<HomeTitleEntity> stringList = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (homeDocModel.homeTitleEntities!=null){
                stringList = homeDocModel.homeTitleEntities;
            }else {
                Document doc = null;
                if (homeDocModel.doc == null) {
                    doc = Jsoup.connect(url).maxBodySize(0).get();
                    homeDocModel.doc = doc;
                }
                doc = homeDocModel.doc;
                Elements navmenu = doc.getElementsByClass("navmenu");
                Elements li = navmenu.get(0).getElementsByTag("li");
                int liCount = li.size();
                for (int i=0; i<liCount; i++){
                    Elements a = li.get(i).getElementsByTag("a");
                    String title = a.text();
                    String href = a.attr("href");
                    stringList.add(new HomeTitleEntity(title,href));
                }
                homeDocModel.homeTitleEntities = stringList;
            }
            return stringList;
        } catch (Exception e) {
            e.printStackTrace();
            return stringList;
        }

    }

    public static List<MovieInfoEntity> getMovieInfo(ViewModelStoreOwner context, String url){
        List<MovieInfoEntity> stringList = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (homeDocModel.homeMovieInfo!=null){
                stringList = homeDocModel.homeMovieInfo;
            }else {
                Document doc = null;
                if (homeDocModel.doc == null) {
                    doc = Jsoup.connect(url).maxBodySize(0).get();
                    homeDocModel.doc = doc;
                }
                doc = homeDocModel.doc;
                Elements trailer = doc.getElementsByClass("layout-box");
                int trailerCount = trailer.size();
                for (int j = 0; j < trailerCount-1; j++) {
                    Element element = trailer.get(j);
                    Element titleS = element.getElementsByClass("box-title").get(0);
                    if (titleS.getElementsByTag("h2")==null || titleS.getElementsByTag("h2").size()==0 || element.getElementsByClass("col-sm-wide-7 col-xs-1 p-xs-0").size()==0){
                        continue;
                    }
                    Element title1 = element.getElementsByTag("h2").get(0);
                    String moveType1 = title1.text();
                    stringList.add(new MovieInfoEntity(moveType1));
                    Elements moveLists = element.getElementsByClass("col-sm-wide-7 col-xs-1 p-xs-0").get(0).getElementsByTag("li");
                    for (int i = 0; i < moveLists.size(); i++) {
                        Element a = moveLists.get(i).getElementsByTag("a").get(0);
                        String imgUrl = a.getElementsByTag("img").get(0).attr("data-original");
                        String movieUrl = a.attr("href");
                        String name = a.attr("title");
                        String type = moveType1;
                        MovieInfoEntity infoEntity = new MovieInfoEntity();
                        infoEntity.setImgUrl(imgUrl);
                        infoEntity.setMovieType(moveType1);
                        infoEntity.setType(type);
                        infoEntity.setName(name);
                        infoEntity.setMovieUrl(movieUrl);
                        stringList.add(infoEntity);
                    }
                }
                homeDocModel.homeMovieInfo = stringList;
            }
            return stringList;
        } catch (Exception e) {
            e.printStackTrace();
            return stringList;
        }

    }

    public static List<MovieInfoEntity> getDianYing(ViewModelStoreOwner context, String url, int page, int movieType, int type){
        url = String.format(url,movieType,page);
        List<MovieInfoEntity> stringList = new ArrayList<>();
        if (page==-2){
            return stringList;
        }
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (isHave(movieType,page,homeDocModel)){
                stringList.addAll(returnList(movieType,homeDocModel));
            }else {
                Document doc = Jsoup.connect(url).maxBodySize(0).get();
                Elements pages = doc.getElementsByClass("ajax-page mt-xs-10");
                if (pages==null || pages.size()==0){
                    return stringList;
                }
                Elements activeE = pages.get(0).getElementsByClass("active hidden-xs");
                if (activeE.size()>0){
                    if (!isSetPage(movieType,homeDocModel,type)){
                        if (type==0) {
                            //电影
                            setPage(movieType, homeDocModel, activeE.get(0).text());
                        }else if (type==1){
                            //电视
                            setPageDianshi(movieType, homeDocModel, activeE.get(0).text());
                        }else if (type==3){
                            //动漫
                            setDongman(movieType, homeDocModel, activeE.get(0).text());
                        }
                    }
                }else {
                    if (type==0) {
                        //电影
                        setPage(movieType, homeDocModel, "-2");
                    }else if (type==1){
                        //电视
                        setPageDianshi(movieType, homeDocModel, "-2");
                    }else if (type==3){
                        //动漫
                        setDongman(movieType,homeDocModel,"-2");
                    }
                }


                Elements panel_bd = doc.getElementsByClass("layout-box").get(0).getElementsByClass("img-list hidden");
                if (panel_bd==null || panel_bd.size()==0)
                    return stringList;
                Elements cat_list_vod = panel_bd.get(0).getElementsByTag("li");
                int count = cat_list_vod.size();
                for (int j = 0; j < count; j++) {
                    Element a = cat_list_vod.get(j).getElementsByTag("a").get(0);
                    String imgUrl = a.getElementsByTag("img").attr("data-original");
                    String movieUrl = a.attr("href");

                    String name = a.attr("title");
                    String movietype = "";

                    MovieInfoEntity infoEntity = new MovieInfoEntity();
                    infoEntity.setImgUrl(imgUrl);
                    infoEntity.setMovieType("");
                    infoEntity.setType(movietype);
                    infoEntity.setName(name);
                    infoEntity.setMovieUrl(movieUrl);
                    stringList.add(infoEntity);
                }
            }
            return stringList;
        } catch (IOException e) {
            e.printStackTrace();
            return stringList;
        }catch (Exception e) {
            e.printStackTrace();
            return stringList;
        }
    }

    private static void setPage(int type, HomeDocModel homeDocModel, String substring){
        switch (type){
            case 1:
                homeDocModel.reBoPages = Integer.parseInt(substring);
                break;
            case 25:
                homeDocModel.reBoPages1 = Integer.parseInt(substring);
                break;
            case 26:
                homeDocModel.reBoPages2 = Integer.parseInt(substring);
                break;
            case 27:
                homeDocModel.reBoPages3 = Integer.parseInt(substring);
                break;
            case 28:
                homeDocModel.reBoPages4 = Integer.parseInt(substring);
                break;
            case 29:
                homeDocModel.reBoPages5 = Integer.parseInt(substring);
                break;
            case 30:
                homeDocModel.reBoPages6 = Integer.parseInt(substring);
                break;
            case 31:
                homeDocModel.reBoPages7 = Integer.parseInt(substring);
                break;
            case 32:
                homeDocModel.reBoPages8 = Integer.parseInt(substring);
                break;
            case 33:
                homeDocModel.reBoPages9 = Integer.parseInt(substring);
                break;
            case 34:
                homeDocModel.reBoPages10 = Integer.parseInt(substring);
                break;
            case 35:
                homeDocModel.reBoPages11 = Integer.parseInt(substring);
                break;
        }
    }

    private static void setDongman(int type, HomeDocModel homeDocModel, String substring){
        switch (type){
            //129,127,130,125,148,126,128,146
            case 3:
                homeDocModel.dongmanPages11 = Integer.parseInt(substring);
                break;
            case 129:
                homeDocModel.dongmanPages12 = Integer.parseInt(substring);
                break;
            case 127:
                homeDocModel.dongmanPages13 = Integer.parseInt(substring);
                break;
            case 130:
                homeDocModel.dongmanPages14 = Integer.parseInt(substring);
                break;
            case 125:
                homeDocModel.dongmanPages15 = Integer.parseInt(substring);
                break;
            case 148:
                homeDocModel.dongmanPages16 = Integer.parseInt(substring);
                break;
            case 126:
                homeDocModel.dongmanPages17 = Integer.parseInt(substring);
                break;
            case 128:
                homeDocModel.dongmanPages18 = Integer.parseInt(substring);
                break;
            case 146:
                homeDocModel.dongmanPages19 = Integer.parseInt(substring);
                break;
        }
    }

    private static void setPageDianshi(int type, HomeDocModel homeDocModel, String substring){
        switch (type){
            case 0:
                homeDocModel.dianShiPages = Integer.parseInt(substring);
                break;
            case 1:
                homeDocModel.dianShiPages1 = Integer.parseInt(substring);
                break;
            case 2:
                homeDocModel.dianShiPages2 = Integer.parseInt(substring);
                break;
            case 3:
                homeDocModel.dianShiPages3 = Integer.parseInt(substring);
                break;
            case 4:
                homeDocModel.dianShiPages4 = Integer.parseInt(substring);
                break;
        }
    }
    private static boolean isSetPage(int type, HomeDocModel homeDocModel, int movieType) {
        boolean seted = true;
        if (movieType==0) {
            switch (type) {
                case 0:
                    if (homeDocModel.reBoPages == -1) {
                        seted = false;
                    }
                    break;
                case 1:
                    if (homeDocModel.reBoPages1 == -1) {
                        seted = false;
                    }
                    break;
                case 2:
                    if (homeDocModel.reBoPages2 == -1) {
                        seted = false;
                    }
                    break;
                case 3:
                    if (homeDocModel.reBoPages3 == -1) {
                        seted = false;
                    }
                    break;
                case 4:
                    if (homeDocModel.reBoPages4 == -1) {
                        seted = false;
                    }
                    break;
                case 5:
                    if (homeDocModel.reBoPages5 == -1) {
                        seted = false;
                    }
                    break;
                case 6:
                    if (homeDocModel.reBoPages6 == -1) {
                        seted = false;
                    }
                    break;
                case 7:
                    if (homeDocModel.reBoPages7 == -1) {
                        seted = false;
                    }
                    break;
                case 8:
                    if (homeDocModel.reBoPages8 == -1) {
                        seted = false;
                    }
                    break;
                case 9:
                    if (homeDocModel.reBoPages9 == -1) {
                        seted = false;
                    }
                    break;
                case 10:
                    if (homeDocModel.reBoPages10 == -1) {
                        seted = false;
                    }
                    break;
                case 11:
                    if (homeDocModel.reBoPages11 == -1) {
                        seted = false;
                    }
                    break;
            }
        }else if (movieType==1){
            return isSetPageDianshi(type,homeDocModel);
        }else if (movieType==2){
            switch (type){
                //129,127,130,125,148,126,128,146
                case 3:
                    if (homeDocModel.dongmanPages11==-1){
                        return false;
                    }
                    break;
                case 129:
                    if (homeDocModel.dongmanPages12==-1){
                        return false;
                    }
                    break;
                case 127:
                    if (homeDocModel.dongmanPages13==-1){
                        return false;
                    }
                    break;
                case 130:
                    if (homeDocModel.dongmanPages14==-1){
                        return false;
                    }
                    break;
                case 125:
                    if (homeDocModel.dongmanPages15==-1){
                        return false;
                    }
                    break;
                case 148:
                    if (homeDocModel.dongmanPages16==-1){
                        return false;
                    }
                    break;
                case 126:
                    if (homeDocModel.dongmanPages17==-1){
                        return false;
                    }
                    break;
                case 128:
                    if (homeDocModel.dongmanPages18==-1){
                        return false;
                    }
                    break;
                case 146:
                    if (homeDocModel.dongmanPages19==-1){
                        return false;
                    }
                    break;
            }
        }
        return seted;
    }
    private static boolean isSetPageDianshi(int type, HomeDocModel homeDocModel) {
        boolean seted = true;
        switch (type){
            case 0:
                if (homeDocModel.dianShiPages ==-1){
                    seted = false;
                }
                break;
            case 1:
                if (homeDocModel.dianShiPages1 ==-1){
                    seted = false;
                }
                break;
            case 2:
                if (homeDocModel.dianShiPages2 ==-1){
                    seted = false;
                }
                break;
            case 3:
                if (homeDocModel.dianShiPages3 ==-1){
                    seted = false;
                }
                break;
            case 4:
                if (homeDocModel.dianShiPages4 ==-1){
                    seted = false;
                }
                break;
        }
        return seted;
    }

    private static boolean isHave(int type, int page, HomeDocModel homeDocModel){
        boolean is = false;
        switch (type){
            case 0:
                if (homeDocModel.reBoPages !=-1 && page==homeDocModel.reBoPages){
                    is = true;
                }
                break;
            case 1:
                if (homeDocModel.reBoPages1 !=-1 && page==homeDocModel.reBoPages1){
                    is = true;
                }
                break;
            case 2:
                if (homeDocModel.reBoPages2 !=-1 && page==homeDocModel.reBoPages2){
                    is = true;
                }
                break;
            case 3:
                if (homeDocModel.reBoPages3 !=-1 && page==homeDocModel.reBoPages3){
                    is = true;
                }
                break;
            case 4:
                if (homeDocModel.reBoPages4 !=-1 && page==homeDocModel.reBoPages4){
                    is = true;
                }
                break;
            case 5:
                if (homeDocModel.reBoPages5 !=-1 && page==homeDocModel.reBoPages5){
                    is = true;
                }
                break;
            case 6:
                if (homeDocModel.reBoPages6 !=-1 && page==homeDocModel.reBoPages6){
                    is = true;
                }
                break;
            case 7:
                if (homeDocModel.reBoPages7 !=-1 && page==homeDocModel.reBoPages7){
                    is = true;
                }
                break;
            case 8:
                if (homeDocModel.reBoPages8 !=-1 && page==homeDocModel.reBoPages8){
                    is = true;
                }
                break;
            case 9:
                if (homeDocModel.reBoPages9 !=-1 && page==homeDocModel.reBoPages9){
                    is = true;
                }
                break;
            case 10:
                if (homeDocModel.reBoPages10 !=-1 && page==homeDocModel.reBoPages10){
                    is = true;
                }
                break;
            case 11:
                if (homeDocModel.reBoPages11 !=-1 && page==homeDocModel.reBoPages11){
                    is = true;
                }
                break;
        }
        return is;
    }

    private static boolean isHaveDianshi(int type, int page, HomeDocModel homeDocModel){
        boolean is = false;
        switch (type){
            case 0:
                if (homeDocModel.dianShiPages !=-1 && page==homeDocModel.dianShiPages){
                    is = true;
                }
                break;
            case 1:
                if (homeDocModel.dianShiPages1 !=-1 && page==homeDocModel.dianShiPages1){
                    is = true;
                }
                break;
            case 2:
                if (homeDocModel.dianShiPages2 !=-1 && page==homeDocModel.dianShiPages2){
                    is = true;
                }
                break;
            case 3:
                if (homeDocModel.dianShiPages3 !=-1 && page==homeDocModel.dianShiPages3){
                    is = true;
                }
                break;
            case 4:
                if (homeDocModel.dianShiPages4 !=-1 && page==homeDocModel.dianShiPages4){
                    is = true;
                }
                break;
        }
        return is;
    }
    private static List<MovieInfoEntity> returnList(int movieType, HomeDocModel homeDocModel){
        List<MovieInfoEntity> stringList = new ArrayList<>();
        switch (movieType){
            case 0:
                stringList.addAll(homeDocModel.movieReBoList);
                break;
            case 1:
                stringList.addAll(homeDocModel.movieReBoList1);
                break;
            case 2:
                stringList.addAll(homeDocModel.movieReBoList2);
                break;
            case 3:
                stringList.addAll(homeDocModel.movieReBoList3);
                break;
            case 4:
                stringList.addAll(homeDocModel.movieReBoList4);
                break;
            case 5:
                stringList.addAll(homeDocModel.movieReBoList5);
                break;
            case 6:
                stringList.addAll(homeDocModel.movieReBoList6);
                break;
            case 7:
                stringList.addAll(homeDocModel.movieReBoList7);
                break;
            case 8:
                stringList.addAll(homeDocModel.movieReBoList8);
                break;
            case 9:
                stringList.addAll(homeDocModel.movieReBoList9);
                break;
            case 10:
                stringList.addAll(homeDocModel.movieReBoList10);
                break;
            case 11:
                stringList.addAll(homeDocModel.movieReBoList11);
                break;
        }
        return stringList;
    }
    private static List<MovieInfoEntity> returnListDianshi(int movieType, HomeDocModel homeDocModel){
        List<MovieInfoEntity> stringList = new ArrayList<>();
        switch (movieType){
            case 0:
                stringList.addAll(homeDocModel.dianShiList);
                break;
            case 1:
                stringList.addAll(homeDocModel.dianShiList1);
                break;
            case 2:
                stringList.addAll(homeDocModel.dianShiList2);
                break;
            case 3:
                stringList.addAll(homeDocModel.dianShiList3);
                break;
            case 4:
                stringList.addAll(homeDocModel.dianShiList4);
                break;
            case 5:
                stringList.addAll(homeDocModel.dianShiList5);
                break;
            case 6:
                stringList.addAll(homeDocModel.dianShiList6);
                break;
            case 7:
                stringList.addAll(homeDocModel.dianShiList7);
                break;
        }
        return stringList;
    }

    public static List<MovieInfoEntity> getDianShi(ViewModelStoreOwner context, String url, int page, int movieType){
        url = url+page+".html";
        List<MovieInfoEntity> stringList = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (isHaveDianshi(movieType,page,homeDocModel)){
                stringList.addAll(returnListDianshi(movieType,homeDocModel));
            }else {
                Document doc = Jsoup.connect(url).maxBodySize(0).get();
                Elements pages = doc.getElementsByClass("myui-page text-center clearfix");
                if (pages==null || pages.size()==0){
                    return stringList;
                }

                Elements lis = pages.get(0).getElementsByTag("li");
                if (!isSetPageDianshi(movieType,homeDocModel)){
                    String href = lis.get(lis.size() - 1).getElementsByTag("a").get(0).attr("href");
                    String substring = href.substring(href.lastIndexOf("/") + 1, href.indexOf(".html"));
//                    homeDocModel.reBoPages = Integer.parseInt(substring);
                    setPageDianshi(movieType,homeDocModel,substring);
                }
                Elements panel_bd = doc.getElementsByClass("myui-vodlist");
                if (panel_bd==null || panel_bd.size()==0)
                    return stringList;
                Elements cat_list_vod = panel_bd.get(0).getElementsByTag("li");
                int count = cat_list_vod.size();
                for (int j = 0; j < count; j++) {
                    Elements a = cat_list_vod.get(j).getElementsByTag("a");
                    String imgUrl = a.get(0).attr("data-original");
                    String movieUrl = a.get(0).attr("href");
                    Element detail = cat_list_vod.get(j).getElementsByClass("myui-vodlist__detail").get(0);
                    String name = detail.getElementsByTag("h4").get(0).text();
                    String type = detail.getElementsByClass("text").get(0).text();

                    MovieInfoEntity infoEntity = new MovieInfoEntity();
                    infoEntity.setImgUrl(imgUrl);
                    infoEntity.setMovieType("");
                    infoEntity.setType(type);
                    infoEntity.setName(name);
                    infoEntity.setMovieUrl(movieUrl);
                    stringList.add(infoEntity);
                }
            }
            return stringList;
        } catch (Exception e) {
            e.printStackTrace();
            return stringList;
        }
    }

    public static List<DongHuaEntity> getDongHua(ViewModelStoreOwner context, String url, int page){
        url = url+page+".html";
        List<DongHuaEntity> dongHuaEntities = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (homeDocModel.donghuaPages !=-1 && page==homeDocModel.donghuaPages){
                dongHuaEntities.addAll(homeDocModel.dongHuaEntities);
            }else {
                Document doc = Jsoup.connect(url).maxBodySize(0).get();
                Elements pages = doc.getElementsByClass("myui-page text-center clearfix");
                if (pages==null || pages.size()==0){
                    return dongHuaEntities;
                }

                Elements lis = pages.get(0).getElementsByTag("li");
                if (homeDocModel.donghuaPages==-1){
                    String href = lis.get(lis.size() - 1).getElementsByTag("a").get(0).attr("href");
                    String substring = href.substring(href.lastIndexOf("/") + 1, href.indexOf(".html"));
                    homeDocModel.donghuaPages = Integer.parseInt(substring);
                }
                Elements panel_bd = doc.getElementsByClass("myui-vodlist");
                if (panel_bd==null || panel_bd.size()==0)
                    return dongHuaEntities;
                Elements cat_list_vod = panel_bd.get(0).getElementsByTag("li");
                int count = cat_list_vod.size();
                for (int j = 0; j < count; j++) {
                    Elements a = cat_list_vod.get(j).getElementsByTag("a");
                    String imgUrl = a.get(0).attr("data-original");
                    String movieUrl = a.get(0).attr("href");
                    Element detail = cat_list_vod.get(j).getElementsByClass("myui-vodlist__detail").get(0);
                    String name = detail.getElementsByTag("h4").get(0).text();
                    Elements spans = a.get(0).getElementsByTag("span");
                    String type = "";
                    String time = "";
                    if (spans.size()>2) {
                        type = "评分："+spans.get(1).text();
                        time = spans.get(2).text();
                    }

                    String desc = "简介：点击查看详情";
                    DongHuaEntity dongHuaEntity = new DongHuaEntity();
                    dongHuaEntity.setName(name);
                    dongHuaEntity.setMoveUrl(movieUrl);
                    dongHuaEntity.setIntroduction(desc);
                    dongHuaEntity.setType(type);
                    dongHuaEntity.setTime(time);
                    dongHuaEntity.setPic(imgUrl);
                    dongHuaEntities.add(dongHuaEntity);
                }
            }
            return dongHuaEntities;
        } catch (Exception e) {
            e.printStackTrace();
            return dongHuaEntities;
        }
    }

    public static List<DongHuaEntity> getZongYi(ViewModelStoreOwner context, String url, int page){
        url = url+page+".html";
        List<DongHuaEntity> dongHuaEntities = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (homeDocModel.zongyiPages !=-1 && page==homeDocModel.zongyiPages){
                dongHuaEntities.addAll(homeDocModel.zongyiEntities);
            }else {
                Document doc = Jsoup.connect(url).maxBodySize(0).get();
                Elements pages = doc.getElementsByClass("myui-page text-center clearfix");
                if (pages==null || pages.size()==0){
                    return dongHuaEntities;
                }

                Elements lis = pages.get(0).getElementsByTag("li");
                String href = lis.get(lis.size() - 1).getElementsByTag("a").get(0).attr("href");
                String substring = href.substring(href.lastIndexOf("/") + 1, href.indexOf(".html"));
                homeDocModel.zongyiPages = Integer.parseInt(substring);

                Elements panel_bd = doc.getElementsByClass("myui-vodlist");
                if (panel_bd==null || panel_bd.size()==0)
                    return dongHuaEntities;
                Elements cat_list_vod = panel_bd.get(0).getElementsByTag("li");
                int count = cat_list_vod.size();
                for (int j = 0; j < count; j++) {
                    Elements a = cat_list_vod.get(j).getElementsByTag("a");
                    String imgUrl = a.get(0).attr("data-original");
                    String movieUrl = a.get(0).attr("href");
                    Element detail = cat_list_vod.get(j).getElementsByClass("myui-vodlist__detail").get(0);
                    String name = detail.getElementsByTag("h4").get(0).text();
                    Elements spans = a.get(0).getElementsByTag("span");
                    String type = "";
                    String time = "";
                    if (spans.size()>2) {
                        type = "评分："+spans.get(2).text();
                        time = spans.get(1).text();
                    }

                    String desc = "简介：点击查看详情";
                    DongHuaEntity dongHuaEntity = new DongHuaEntity();
                    dongHuaEntity.setName(name);
                    dongHuaEntity.setMoveUrl(movieUrl);
                    dongHuaEntity.setIntroduction(desc);
                    dongHuaEntity.setType(type);
                    dongHuaEntity.setTime(time);
                    dongHuaEntity.setPic(imgUrl);
                    dongHuaEntities.add(dongHuaEntity);
                }
            }
            return dongHuaEntities;
        } catch (Exception e) {
            e.printStackTrace();
            return dongHuaEntities;
        }
    }

    public static List<DongHuaEntity> getLive(ViewModelStoreOwner context, String url, int page){
        url = url+page+".html";
        List<DongHuaEntity> dongHuaEntities = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            if (homeDocModel.zongyiPages !=-1 && page==homeDocModel.zongyiPages){
                dongHuaEntities.addAll(homeDocModel.zongyiEntities);
            }else {
                Document doc = Jsoup.connect(url).maxBodySize(0).get();

                Elements pagesa = doc.getElementsByClass("pages").get(0).getElementsByTag("a");
                String href = pagesa.get(pagesa.size() - 2).attr("href");
                String substring = href.substring(href.lastIndexOf("_") + 1, href.indexOf(".html"));
                homeDocModel.zongyiPages = Integer.parseInt(substring);
                Elements line_middle = doc.getElementsByClass("line-middle");
                int count = line_middle.size();
                for (int j = 1; j < count; j++) {
                    Element lineItem = line_middle.get(j);
                    Elements tagbox_pic = lineItem.getElementsByClass("tagbox_pic");
                    Elements img = tagbox_pic.get(0).getElementsByTag("a").get(0).getElementsByTag("img");

                    Elements tagbox_info = lineItem.getElementsByClass("tagbox_info");
                    Elements title1 = tagbox_info.get(0).getElementsByTag("h2").get(0).getElementsByTag("a");
                    String name = title1.get(0).attr("title");
                    String movieUrl = title1.attr("href");
                    String imgUrl = img.get(0).attr("src");

                    Elements ps = tagbox_info.get(0).getElementsByTag("p");
                    String desc = ps.get(0).text();

                    String time = ps.get(ps.size()-1).text();

                    DongHuaEntity dongHuaEntity = new DongHuaEntity();
                    dongHuaEntity.setName(name);
                    dongHuaEntity.setMoveUrl(movieUrl);
                    dongHuaEntity.setIntroduction(desc);
                    dongHuaEntity.setType("");
                    dongHuaEntity.setTime(time);
                    dongHuaEntity.setPic(imgUrl);
                    dongHuaEntities.add(dongHuaEntity);
                }
            }
            return dongHuaEntities;
        } catch (Exception e) {
            e.printStackTrace();
            return dongHuaEntities;
        }
    }

    public static List<DongHuaEntity> getSearch(ViewModelStoreOwner context, String url, String search, int page){
        url = url+"wd="+search+"&p="+page;
        List<DongHuaEntity> dongHuaEntities = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            Document doc = Jsoup.connect(url).maxBodySize(0).get();

            Elements line_middle = doc.getElementsByClass("img-list clearfix news-list").get(0).getElementsByTag("li");
            if (line_middle==null || line_middle.size()==0){
                Log.d("search","没有数据");
            }else {
                Element pageElements = doc.getElementById("page");
                if (pageElements==null){
                    homeDocModel.searchPages = -1;
                }else {
                    Elements pagesa = pageElements.getElementsByTag("li");
                    if (pagesa.size() == 0) {
                        homeDocModel.searchPages = -1;
                    } else {
                        String substring = pageElements.getElementsByClass("active hidden-xs").get(0).text();
                        homeDocModel.searchPages = Integer.parseInt(substring);
                    }
                }

                int count = line_middle.size();
                for (int j = 0; j < count; j++) {
                    Element lineItem = line_middle.get(j);
                    Element tagbox_pic = lineItem.getElementsByClass("img-pic").get(0);
                    String imgUrl = tagbox_pic.getElementsByTag("img").get(0).attr("data-original");
                    String movieUrl = tagbox_pic.attr("href");

                    Element detail = lineItem.getElementsByClass("col-md-wide-75 col-sm-wide-65 col-xs-wide-65 pl-md-20 pl-xs-10 pt-xs-0 pb-xs-0").get(0);
                    String name = detail.getElementsByClass("text-overflow").get(0).text();

                    String desc = detail.getElementsByClass("text-muted hidden-xs vod-txt").get(0).text();

                    String time = detail.getElementsByClass("hidden-xs col-sm-2 col-xs-1 text-muted pl-xs-0").get(0).text();
                    String type = detail.getElementsByClass("hidden-xs col-sm-2 col-xs-1 text-muted").get(0).text();

                    DongHuaEntity dongHuaEntity = new DongHuaEntity();
                    dongHuaEntity.setName(name);
                    dongHuaEntity.setMoveUrl(movieUrl);
                    dongHuaEntity.setIntroduction(desc);
                    dongHuaEntity.setType(type);
                    dongHuaEntity.setTime(time);
                    dongHuaEntity.setPic(imgUrl);
                    dongHuaEntities.add(dongHuaEntity);
                }
            }
            return dongHuaEntities;
        } catch (Exception e) {
            e.printStackTrace();
            return dongHuaEntities;
        }
    }

    public static List<PlayListEntity> getMovieDetail(String url){
        List<PlayListEntity> returnPlayLists = new ArrayList<>();
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();

            MovieDetailEntity movieDetailEntity = new MovieDetailEntity();
            Elements imgElement = doc.getElementsByClass("vod-detail-thumb");
            Element img = imgElement.get(0).getElementsByTag("img").get(0);
            String imgUrl = img.attr("src");
            Element detailElement = doc.getElementsByClass("col-sm-wide-7 col-xs-wide-65 vod-detail-info pt-xs-0").get(0);
            String name = detailElement.getElementsByClass("col-xs-1").get(0).getElementsByTag("h1").get(0).text();

            String src = "";
            String type = "";
            String year = "";
            String desc = "";
            Elements statueE = detailElement.getElementsByClass("col-sm-2 col-xs-1");
            if (statueE.size()>0){
                src = statueE.get(0).text();
            }
            Elements typeE = detailElement.getElementsByClass("col-xs-1 text-overflow");
            if (typeE.size()>0){
                src = typeE.get(0).text();
            }
            Elements yearE = detailElement.getElementsByClass("col-sm-2 col-xs-1 text-overflow hidden-xs");
            if (yearE.size()>1){
                year = yearE.get(2).text();
            }
            Elements descE = detailElement.getElementsByClass("col-xs-1 detail-info hidden-xs");
            if (descE.size()>0){
                desc = descE.get(0).text();
            }else {
                desc = "简介：";
            }


            movieDetailEntity.setImgUrl(imgUrl);
            movieDetailEntity.setDesc(desc);
            movieDetailEntity.setName(name);
            movieDetailEntity.setYear(year);
            movieDetailEntity.setType(type);
            movieDetailEntity.setSrc(src);

            Elements navTabs = doc.getElementsByClass("details-play-title clearfix").get(0).getElementById("Tab").getElementsByTag("li");
            for (int i=0;i<navTabs.size();i++){
                PlayListEntity listEntity = new PlayListEntity();
                listEntity.setMovieDetail(movieDetailEntity);
                listEntity.setName(navTabs.get(i).text());
                returnPlayLists.add(i,listEntity);
            }

            Elements sortLists = doc.getElementsByClass("details-play-list clearfix p-sm-5 p-xs-0 mt-xs-10").get(0).getElementsByTag("ul");
            for (int i=0;i<sortLists.size();i++){
                Elements lists = sortLists.get(i).getElementsByTag("li");
                List<MoviePlayerEntity> playerEntities = new ArrayList<>();
                for (int j=0;j<lists.size();j++){
                    MoviePlayerEntity moviePlayerEntity = new MoviePlayerEntity();
                    Element elementa = lists.get(j).getElementsByTag("a").get(0);
                    String playName = elementa.text();
                    String playUrl = elementa.attr("href");
                    moviePlayerEntity.setName(playName);
                    moviePlayerEntity.setUrl(playUrl);
                    playerEntities.add(moviePlayerEntity);
                }
                returnPlayLists.get(i).setPlayLists(playerEntities);
            }

            return returnPlayLists;
        }catch (Exception e){
            return returnPlayLists;
        }
    }

    public static List<List> getPanelBody(String url){
        List<List> returnList = new ArrayList<>();
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();

            String m3u8 = "";
            Element zanpiancms_player = doc.getElementById("zanpiancms_player");
            Element cms_play = zanpiancms_player.getElementById("cms_play");

            Elements script = cms_play.getElementsByTag("script");
            Elements allElements = script.get(0).getAllElements();
            Element element0 = allElements.get(0);
            String src = element0.data();
            List<String> m3u8List = new ArrayList<>();
            if (!src.contains("=")){
                return returnList;
            }
            String substring = src.substring(src.indexOf("=") + 1,src.length()-1);
            JSONObject json = new JSONObject().parseObject(substring);
            m3u8 = json.getString("url");
            m3u8List.add(m3u8);
            returnList.add(m3u8List);

            List<PlayListEntity> returnPlayLists = new ArrayList<>();
            Elements dropdown_box = doc.getElementsByClass("player-more-list").get(0).getElementsByTag("li");
            for (int i=0;i<dropdown_box.size();i++){
                PlayListEntity listEntity = new PlayListEntity();
                listEntity.setName(dropdown_box.get(i).text());
                returnPlayLists.add(i,listEntity);
            }


            Elements sortLists = doc.getElementsByClass("details-play-list min-play-list clearfix p-sm-5 p-xs-0").get(0).getElementsByTag("ul");
            for (int i=0;i<sortLists.size();i++){
                Elements lists = sortLists.get(i).getElementsByTag("li");
                List<MoviePlayerEntity> playerEntities = new ArrayList<>();
                for (int j=0;j<lists.size();j++){
                    MoviePlayerEntity moviePlayerEntity = new MoviePlayerEntity();
                    Element elementa = lists.get(j).getElementsByTag("a").get(0);
                    String playName = elementa.text();
                    String playUrl = elementa.attr("href");
                    moviePlayerEntity.setName(playName);
                    moviePlayerEntity.setUrl(playUrl);
                    playerEntities.add(moviePlayerEntity);
                }
                returnPlayLists.get(i).setPlayLists(playerEntities);
            }

            returnList.add(returnPlayLists);

            String name = "";
            Elements play_vbox = doc.getElementsByClass("col-sm-wide-25 col-xs-1 player-right");
            Elements elementsByClass = play_vbox.get(0).getElementsByClass("p-xs-10 player-tips clearfix");

            Elements h5 = elementsByClass.get(0).getElementsByTag("h5");
            name = h5.get(0).getElementsByClass("pull-left").get(0).text();
            List<String> nameList = new ArrayList<>();
            nameList.add(name);
            returnList.add(nameList);

            return returnList;
        }catch (Exception e){
            e.printStackTrace();
            return returnList;
        }
    }
    public static String getTsM3u8(String url){
        String m3u8="";
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements container = doc.getElementsByClass("container");
            Elements player_video = container.get(0).getElementsByClass("player_video");
            Elements script = player_video.get(0).getElementsByTag("script");
            Elements allElements = script.get(0).getAllElements();
            Element element0 = allElements.get(0);
            String src = element0.data();
            if (src.contains("http") && src.contains(".m3u8")) {
                m3u8 = src.substring(src.indexOf("http"), src.indexOf(".m3u8") + 5);
            }
            return m3u8;
        } catch (Exception e) {
            e.printStackTrace();
            return m3u8;
        }
    }

    public static HashMap<String,String> getM3u8(String url){
        HashMap<String,String> map = new HashMap<>();
        String m3u8="";
        String wh="";
        try {
            URL url1 = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
            if (conn.getResponseCode() == 200){
                InputStream is = conn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                String line = "";
                while ((line = reader.readLine())!=null){
                    if (line.endsWith(".m3u8")){
                        m3u8 = line;
                        map.put("m3u8",m3u8);
                    }else if (line.contains("RESOLUTION")){
                        wh = line.substring(line.indexOf("RESOLUTION=")+11);
                        map.put("wh",wh);
                    }
                }
                is.close();
            }
            return map;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return map;
        }
    }

    public static List<List> getTs(String url){
        List<String> allTs = new ArrayList<>();
        List<Float> allTimes = new ArrayList<>();
        List<List> returnList = new ArrayList<>();
        List<HashMap> encode = new ArrayList<>();
        HashMap map = new HashMap();
        map.put("method","");
        map.put("key","");
        map.put("iv","");
        try {
            URL url1 = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
            if (conn.getResponseCode() == 200){
                InputStream is = conn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                String line = "";
                while ((line = reader.readLine())!=null){
                    if (line.contains("EXT-X-KEY")) {
                        String[] split1 = line.split(",");
                        for (String s1 : split1) {
                            if (s1.contains("METHOD")) {
                                String method = s1.split("=", 2)[1];
                                map.put("method",method);
                                continue;
                            }
                            if (s1.contains("URI")) {
                                String key = s1.split("=", 2)[1];
                                map.put("key",key);
                                continue;
                            }
                            if (s1.contains("IV")) {
                                String iv = s1.split("=", 2)[1];
                                map.put("iv",iv);
                            }
                        }
                        encode.add(map);
                    }else if (line.length()>0 && (line.endsWith(".ts") || line.endsWith(".jpg") || line.toLowerCase().endsWith(".png"))){
                        allTs.add(line);
                    }else if (line.startsWith("#EXTINF:")){
                        String substring = line.substring(line.lastIndexOf(":") + 1, line.length()-1);
                        allTimes.add(Float.valueOf(substring));
                    }
                }
                returnList.add(allTs);
                returnList.add(allTimes);
                returnList.add(encode);
                is.close();
            }
            return returnList;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return returnList;
        } catch (Exception e) {
            e.printStackTrace();
            return returnList;
        }
    }

    public static String getTsM3u82(String url){
        String m3u8="";
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements playleft = doc.getElementsByClass("play_wrap");

            Elements script = playleft.get(0).getElementsByTag("script");
            Elements allElements = script.get(0).getAllElements();
            Element element0 = allElements.get(0);
            String src = element0.data();

            if (src.contains("http") && src.contains(".m3u8")) {
                m3u8 = URLDecoder.decode(src.substring(src.lastIndexOf("http"), src.lastIndexOf(".m3u8") + 5));
                /*if (src.split("http").length>2){
                    String home = m3u8.substring(0,m3u8.indexOf(".com/")+4);
                    m3u8 = home + getM3u8HomeUrl(m3u8);
                }*/
            }
            Log.d("m3u8==",m3u8);
            return src;
        } catch (Exception e) {
            e.printStackTrace();
            return m3u8;
        }
    }

    public static List<PlayListEntity> getMovieDetail2(String url){
        List<PlayListEntity> returnPlayLists = new ArrayList<>();
        try {
            MovieDetailEntity movieDetailEntity = new MovieDetailEntity();
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements bodycon_thumb = doc.getElementsByClass("img_wrap");
            Element img = bodycon_thumb.get(0).getElementsByTag("img").get(0);
            String imgUrl = img.attr("data-original");
            String name = img.attr("alt");

            Elements detail_wrap = doc.getElementsByClass("detail_wrap");
            Elements lis = detail_wrap.get(0).getElementsByTag("li");
            String src = lis.get(1).text();
            String type = lis.get(2).text()+"   "+lis.get(3).text()+"   "+lis.get(4).text();
            String year = lis.get(5).text();
            String desc = lis.get(6).text();

            movieDetailEntity.setImgUrl(imgUrl);
            movieDetailEntity.setDesc(desc);
            movieDetailEntity.setName(name);
            movieDetailEntity.setYear(year);
            movieDetailEntity.setType(type);
            movieDetailEntity.setSrc(src);

            Elements playlist = doc.getElementsByClass("playlist big_shadow mt30");
            for (int i=0;i<playlist.size();i++){
                List<MoviePlayerEntity> playerEntities = new ArrayList<>();
                Element element = playlist.get(i);
                Element header = element.getElementsByClass("header").get(0);
                Elements as = element.getElementsByClass("mlist").get(0).getElementsByTag("a");
                PlayListEntity listEntity = new PlayListEntity();
                listEntity.setMovieDetail(movieDetailEntity);
                listEntity.setName(header.getElementsByTag("h4").get(0).text());
                for (int j=0;j<as.size();j++) {
                    Element a = as.get(j);
                    String playName = a.text();
                    String playUrl = a.attr("href");
                    MoviePlayerEntity moviePlayerEntity = new MoviePlayerEntity();
                    moviePlayerEntity.setName(playName);
                    moviePlayerEntity.setUrl(playUrl);
                    playerEntities.add(moviePlayerEntity);
                }
                listEntity.setPlayLists(playerEntities);
                returnPlayLists.add(i,listEntity);
            }

            return returnPlayLists;
        }catch (Exception e){
            return returnPlayLists;
        }
    }

    public static List<List>  getMovieList(String url){
        List<List> returnList = new ArrayList<>();
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements playleft = doc.getElementsByClass("play_wrap");

            List<String> srcList = new ArrayList<>();
            Elements script = playleft.get(0).getElementsByTag("script");
            Elements allElements = script.get(0).getAllElements();
            Element element0 = allElements.get(0);
            String src = element0.data();
            srcList.add(src);
            returnList.add(srcList);

            List<PlayListEntity> returnPlayLists = new ArrayList<>();
            Elements playlist = doc.getElementsByClass("playlist big_shadow mt30");
            for (int i=0;i<playlist.size();i++){
                List<MoviePlayerEntity> playerEntities = new ArrayList<>();
                Element element = playlist.get(i);
                Element header = element.getElementsByClass("header").get(0);
                Elements as = element.getElementsByClass("mlist").get(0).getElementsByTag("a");
                PlayListEntity listEntity = new PlayListEntity();
                listEntity.setName(header.getElementsByTag("h4").get(0).text());
                for (int j=0;j<as.size();j++) {
                    Element a = as.get(j);
                    String playName = a.text();
                    String playUrl = a.attr("href");
                    MoviePlayerEntity moviePlayerEntity = new MoviePlayerEntity();
                    moviePlayerEntity.setName(playName);
                    moviePlayerEntity.setUrl(playUrl);
                    playerEntities.add(moviePlayerEntity);
                }
                listEntity.setPlayLists(playerEntities);
                returnPlayLists.add(i,listEntity);
            }
            returnList.add(returnPlayLists);


            List<String> nameList = new ArrayList<>();
            Elements mt30 = doc.getElementsByClass("mt30");
            Elements h1 = mt30.get(1).getElementsByTag("a");
            String name = h1.get(2).text();
            nameList.add(name);
            returnList.add(nameList);

//            return playerEntities;
            return returnList;
        }catch (Exception e){
            e.printStackTrace();
            return returnList;
        }
    }

    public static String getMovieName(String url){
        String name="";
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements play_vbox = doc.getElementsByClass("play_vbox");
            Elements h1 = play_vbox.get(0).getElementsByTag("h1");
            name = h1.get(0).getElementsByTag("a").get(0).text();
            return name;
        }catch (Exception e){
            e.printStackTrace();
            return name;
        }
    }

    public static String getMovieName2(String url){
        String name="";
        try {
            Document doc = Jsoup.connect(url).maxBodySize(0).get();
            Elements mt30 = doc.getElementsByClass("mt30");
            Elements h1 = mt30.get(1).getElementsByTag("a");
            name = h1.get(2).text();
            return name;
        }catch (Exception e){
            e.printStackTrace();
            return name;
        }
    }

    public static List<DongHuaEntity> getSearch2(ViewModelStoreOwner context, String url, String search, int page){
        url = url+page+"-wd-"+search+".html";
        List<DongHuaEntity> dongHuaEntities = new ArrayList<>();
        try {
            HomeDocModel homeDocModel = new ViewModelProvider(context).get(HomeDocModel.class);
            Document doc = Jsoup.connect(url).maxBodySize(0).get();

            if (doc.getElementsByClass("pages")==null || doc.getElementsByClass("pages").size()==0){
                Log.d("search","没有数据");
            }else {
                Elements pagesa = doc.getElementsByClass("pages");
                String pageText = pagesa.get(0).text();
                String substring = pageText.substring(pageText.indexOf("/")+1,pageText.indexOf("页"));
//                String href = pagesa.get(pagesa.size()-1).attr("href");
//                String substring = href.substring(href.lastIndexOf("vod-search-pg-") + 14, href.lastIndexOf("-wd"));
                homeDocModel.searchPages = Integer.parseInt(substring);
                Elements p_sch_minH = doc.getElementsByClass("p_sch minH");
                Elements lis = p_sch_minH.get(0).getElementsByTag("li");
                int count = lis.size();
                for (int j = 0; j < count; j++) {
                    Element lineItem = lis.get(j);
                    Elements a = lineItem.getElementsByTag("a");
                    Element element = a.get(0);
                    Elements img = element.getElementsByTag("img");
                    String name = a.attr("title");
                    String movieUrl = a.attr("href");
                    String imgUrl = img.get(0).attr("data-original");

                    Elements note = lineItem.getElementsByClass("note");
                    Elements ps = lineItem.getElementsByTag("p");
                    String desc = note.get(0).text();
                    String type = ps.get(1).text();
                    String time = ps.get(2).text();

                    DongHuaEntity dongHuaEntity = new DongHuaEntity();
                    dongHuaEntity.setName(name);
                    dongHuaEntity.setMoveUrl(movieUrl);
                    dongHuaEntity.setIntroduction(desc);
                    dongHuaEntity.setType(type);
                    dongHuaEntity.setTime(time);
                    dongHuaEntity.setPic(imgUrl);
                    dongHuaEntities.add(dongHuaEntity);
                }
            }
            return dongHuaEntities;
        } catch (Exception e) {
            e.printStackTrace();
            return dongHuaEntities;
        }
    }


    /**
     * 模拟http请求获取内容
     *
     * @param urls  http链接
     * @param isKey 这个url链接是否用于获取key
     * @return 内容
     */
    public static HashMap getUrlContent(String urls, boolean isKey) {
        int count = 1;
        HttpURLConnection httpURLConnection = null;
        StringBuilder content = new StringBuilder();
        int retryCount = 5;
        boolean isByte = false;
        byte[] keyBytes = new byte[16];
        HashMap map = new HashMap();
        while (count <= retryCount) {
            try {
                URL url = new URL(urls);
                httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setConnectTimeout((int) 5000);
                httpURLConnection.setReadTimeout((int) 5000);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setDoInput(true);
                httpURLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
                String line;
                InputStream inputStream = httpURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                if (isKey) {
                    byte[] bytes = new byte[128];
                    int len;
                    len = inputStream.read(bytes);
                    isByte = true;
                    map.put("isByte",isByte);
                    if (len == 1 << 4) {
                        keyBytes = Arrays.copyOf(bytes, 16);
                        content.append("isByte");
                        map.put("keyBytes",keyBytes);
                        map.put("content",content);
                    } else {
                        content.append(new String(Arrays.copyOf(bytes, len)));
                        map.put("content",content);
                    }
                    return map;
                }
                while ((line = bufferedReader.readLine()) != null)
                    content.append(line).append("\n");
                map.put("content",content);
                bufferedReader.close();
                inputStream.close();
//                    System.out.println(content);
                break;
            } catch (Exception e) {
//                    System.out.println("第" + count + "获取链接重试！\t" + urls);
                count++;
//                    e.printStackTrace();
            } finally {
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
            }
        }
        return map;
    }
}
